﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADA.Entity;
using ADA.Business;
using System.IO;

namespace ADA.Presentation.PRL.Account
{
    public partial class UserAccDetailForm : Form
    {
        long userID;
        MainForm main;
        public UserAccDetailForm(MainForm Main, long UserID)
        {
            main = Main;
            userID = UserID;
            InitializeComponent();
        }

        private void UserAccDetailForm_Load(object sender, EventArgs e)
        {
            DataTable tblUser;
            string message;
            BOLAccount bolAcc = new BOLAccount();
            if (bolAcc.viewUserDetail(userID, out tblUser, out message) == true)
            {
                User user = new User();
                string province = "";
                if (tblUser.Rows.Count == 1)
                {
                    user.ID = userID;
                    user.Name = Convert.ToString(tblUser.Rows[0]["Name"]).Trim();
                    user.Password = Convert.ToString(tblUser.Rows[0]["Password"]).Trim();
                    user.ProfilePicture = Convert.ToString(tblUser.Rows[0]["ProfilePicture"]).Trim();
                    user.Email = Convert.ToString(tblUser.Rows[0]["Email"]).Trim();
                    user.Phone = Convert.ToString(tblUser.Rows[0]["Phone"]).Trim();
                    user.Address = Convert.ToString(tblUser.Rows[0]["Address"]).Trim();
                    user.ProvinceID = Convert.ToInt16(tblUser.Rows[0]["ProvinceID"]);
                    user.RegisterDate = Convert.ToDateTime(tblUser.Rows[0]["RegisterDate"]);
                    user.ViolationNum = Convert.ToInt16(tblUser.Rows[0]["ViolationNumber"]);
                    user.Status = Convert.ToBoolean(tblUser.Rows[0]["Status"]);

                    province = Convert.ToString(tblUser.Rows[0]["Province"]).Trim();
                }

                lblUserID.Text = user.ID.ToString();
                lblName.Text = user.Name.ToString();
                string pictureName = Path.GetFileName(user.ProfilePicture);
                img.ImageLocation = Common.URL_PROFILE_IMAGE + pictureName;
                lblEmail.Text = user.Email.ToString();
                lblPhone.Text = user.Phone.ToString();
                lblAddress.Text = user.Address.ToString() + ", " + province;
                lblRegisterDate.Text = user.RegisterDate.ToString();

                if (user.RegisterDate.Equals(new DateTime())==true)
                {
                    lblStatus.Text = "Locked";
                }
                else if (user.Status == false)
                    {
                        lblStatus.Text = "Not confirm";
                    }
                    else
                    {
                        lblStatus.Text = "Confirmed";
                    }
            lblViolationNumber.Text = user.ViolationNum.ToString();
            }
            else
            {
                MessageBox.Show(message);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            main.btnDeleteUserAcc_Click(sender, e);
            this.Close();
        }
    }
}
